package com.schoolcloud.front.controller;

import com.schoolcloud.common.model.R;
import com.schoolcloud.front.entity.NotificationTemplates;
import com.schoolcloud.front.query.NotificationTemplateQuery;
import com.schoolcloud.front.service.NotificationTemplatesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/front/notification/template")
@RequiredArgsConstructor
public class NotificationTemplateController {
    private final NotificationTemplatesService notificationTemplateService;

    @PostMapping
    public R<?> saveNotificationTemplate(@RequestBody NotificationTemplates notificationTemplate) {
        return notificationTemplateService.saveNotificationTemplate(notificationTemplate) ? R.ok("保存成功", null) : R.err("保存失败");
    }

    @PutMapping
    public R<?> updateNotificationTemplate(@RequestBody NotificationTemplates notificationTemplate) {
        notificationTemplate.setUpdateTime(LocalDateTime.now());
        return notificationTemplateService.updateById(notificationTemplate) ? R.ok("更新成功", null) : R.err("更新失败");
    }

    @GetMapping("{id}")
    public R<?> getNotificationTemplate(@PathVariable String id) {
        return R.ok("查询成功", notificationTemplateService.getById(id));
    }

    @GetMapping("/page")
    public R<?> getNotificationTemplatePage(NotificationTemplateQuery query) {
        return R.ok("查询成功", notificationTemplateService.getNotificationTemplatePage(query));
    }

}
